if (typeof (mediator) == 'undefined')
	mediator = {};

if (typeof (mediator.teachingList) == 'undefined')
	mediator.teachingList = {};

mediator.teachingList.AppView = function(){
	var self = this;
	
	self.total = ko.observable(0);
	self.teachings = ko.observableArray();
	self.pageSize = ko.observable(10);
	self.removeAllTeachings = function(){
		self.teachings.removeAll(self.teachings());
		self.teachings([]);
	};
	return this;
};


mediator.teachingList.createViewMediator = function(options){
	var settings = $.extend({
		pid : 0,
		type : 'lasts',
		currentPage : 1, 
		pageSize : 10
	}, options || {});
	var appView = new mediator.teachingList.AppView();
	var data = mediator.teachingList.loadData(settings)
	pushTeachingsArray(data.teaches, appView.teachings());
	appView.total(data.total);
	appView.pageSize(data.pageSize);
	mediator.teachingList.renderView();
	return appView;
};



mediator.teachingList.loadData = function(settings){
	if(settings.pid > 0){
		return getPersonsTeachings(settings.pid);
	}
	return getOtherPeoplesTeachings(settings.type, settings.currentPage, settings.pageSize);
};


mediator.teachingList.renderView = function (){
	$('#unTeach').attr('data-bind', 'if : teachings().length == 0');
	$('#teaches').attr('data-bind', 'foreach:teachings, visible : teachings().length != 0');
	$('#teachCourseName').attr('data-bind', 'text:course().name, click : courseView ');
	$('#teachRepeatSummaryV').attr('data-bind', 'visible : repeat().summary');
	$('#teachRepeatSummary').attr('data-bind', 'text:repeat().summary');
	$('#teachCouseTagV').attr('data-bind', 'visible: course().tag');
	$('#teachCouseTag').attr('data-bind', 'text:course().tag');
	$('#teachCourseDescription').attr('data-bind', 'text:course().description');
};